package com.yanqu.road.server.cmd.activity.yearMaster;

import com.yanqu.road.entity.activity.yearMaster.UserYearMasterDataResult;
import com.yanqu.road.pb.yearMaster.YearMasterProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.yearMaster.YearMasterModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

@Cmd(code = GameProtocol.S_YEAR_MASTER_GRID_CHOOSE, desc = "瑞兽降福消除格子")
public class YearMasterChooseGridCmd extends AbstractCommand {


    private int type;
    private List<Integer> indexList;
    private UserYearMasterDataResult userYearMasterDataResult;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        YearMasterProto.YearMasterChooseGridReqMsg req = YearMasterProto.YearMasterChooseGridReqMsg.parseFrom(packet.getBytes());

        indexList = req.getGridIndexList();
        type = req.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        userYearMasterDataResult = player.getModule(YearMasterModule.class).playGame(indexList, type);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (userYearMasterDataResult.getRet() != 0) {
            YearMasterProto.YearMasterChooseGridRspMsg.Builder resp = YearMasterProto.YearMasterChooseGridRspMsg.newBuilder();
            resp.setRet(userYearMasterDataResult.getRet());
            player.sendPacket(ClientProtocol.U_YEAR_MASTER_GRID_CHOOSE, resp);
        }
        //正常由跨服响应
    }
}
